// boxGeometry.ts 

import PipelineObject from '../interface/pipelineObject';
import Geometry from './geometry';

export default class BoxGeometry extends Geometry {
    constructor(width: number, height: number, depth: number, pipeline: PipelineObject) {
        super(new Float32Array(), new Uint16Array([]), 0, 0, pipeline);

        this.setBoxData(width, height, depth);
    }

    private setBoxData(width: number, height: number, depth: number) {
        const halfWidth = width / 2;
        const halfHeight = height / 2;
        const halfDepth = depth / 2;

        const vertices = new Float32Array([
            // Front face
            -halfWidth, -halfHeight, halfDepth, 0, 0, 1, 0, 0,
            halfWidth, -halfHeight, halfDepth, 0, 0, 1, 1, 0,
            halfWidth, halfHeight, halfDepth, 0, 0, 1, 1, 1,
            -halfWidth, halfHeight, halfDepth, 0, 0, 1, 0, 1,

            // Back face
            -halfWidth, -halfHeight, -halfDepth, 0, 0, -1, 1, 0,
            halfWidth, -halfHeight, -halfDepth, 0, 0, -1, 0, 0,
            halfWidth, halfHeight, -halfDepth, 0, 0, -1, 0, 1,
            -halfWidth, halfHeight, -halfDepth, 0, 0, -1, 1, 1,

            // Top face
            -halfWidth, halfHeight, -halfDepth, 0, 1, 0, 0, 1,
            -halfWidth, halfHeight, halfDepth, 0, 1, 0, 1, 1,
            halfWidth, halfHeight, halfDepth, 0, 1, 0, 1, 0,
            halfWidth, halfHeight, -halfDepth, 0, 1, 0, 0, 0,

            // Bottom face
            -halfWidth, -halfHeight, -halfDepth, 0, -1, 0, 1, 1,
            halfWidth, -halfHeight, -halfDepth, 0, -1, 0, 0, 1,
            halfWidth, -halfHeight, halfDepth, 0, -1, 0, 0, 0,
            -halfWidth, -halfHeight, halfDepth, 0, -1, 0, 1, 0,

            // Right face
            halfWidth, -halfHeight, -halfDepth, 1, 0, 0, 0, 1,
            halfWidth, halfHeight, -halfDepth, 1, 0, 0, 1, 1,
            halfWidth, halfHeight, halfDepth, 1, 0, 0, 1, 0,
            halfWidth, -halfHeight, halfDepth, 1, 0, 0, 0, 0,

            // Left face 
            -halfWidth, -halfHeight, -halfDepth, -1, 0, 0, 1, 1,
            -halfWidth, halfHeight, -halfDepth, -1, 0, 0, 0, 1,
            -halfWidth, halfHeight, halfDepth, -1, 0, 0, 0, 0,
            -halfWidth, -halfHeight, halfDepth, -1, 0, 0, 1, 0
        ]);

        const indices = new Uint16Array([
            // Front face
            0, 1, 2,
            2, 3, 0,

            // Back face
            4, 6, 5,
            6, 4, 7,

            // Top face
            8, 9, 10,
            10, 11, 8,

            // Bottom face
            12, 13, 14,
            14, 15, 12,

            // Right face
            16, 17, 18,
            18, 19, 16,

            // Left face
            20, 22, 21,
            22, 20, 23
        ]);

        this.setVertexData(vertices);
        this.setIndexData(indices);
    }
}